<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>2025，蛇年快乐！</title>
  <style>
    html, body {
      width: 100%;
      height: 100%;
    }
    body {
      margin: 0;
      overflow: hidden;
      background: black;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      color: white;
      font-family: Arial, sans-serif;
      font-weight: 900;
      font-size: 60px;
      text-align: center;
      display: flex;
    }
    #text {
      position: absolute;
      white-space: nowrap;
      z-index: 9999;
    }
    canvas {
      position: absolute;
    }
  </style>
</head>
<body>
  <div id="text">2025 蛇年快乐！祝大家的生活如春日繁花般绚烂多彩，事业如旭日东升般蒸蒸日上。</div>
  <canvas id="animationCanvas"></canvas>
  <script>
    class Shard {
      constructor(x, y, hue) {
        this.x = x;
        this.y = y;
        this.hue = hue;
        this.lightness = 50;
        this.size = 15 + Math.random() * 10;
        const angle = Math.random() * 2 * Math.PI;
        const blastSpeed = 1 + Math.random() * 6;
        this.xSpeed = Math.cos(angle) * blastSpeed;
        this.ySpeed = Math.sin(angle) * blastSpeed;
        this.target = getTarget();
        this.ttl = 100;
        this.timer = 0;
      }
      draw(ctx) {
        ctx.fillStyle = `hsl(${this.hue}, 100%, ${this.lightness}%)`;
        ctx.beginPath();
        ctx.arc(this.x, this.y, this.size, 0, 2 * Math.PI);
        ctx.closePath();
        ctx.fill();
      }
      update() {
        if (this.target) {
          const dx = this.target.x - this.x;
          const dy = this.target.y - this.y;
          const dist = Math.sqrt(dx * dx + dy * dy);
          const a = Math.atan2(dy, dx);
          const tx = Math.cos(a) * 5;
          const ty = Math.sin(a) * 5;
          this.size = lerp(this.size, 1.5, 0.05);

          if (dist < 5) {
            this.lightness = lerp(this.lightness, 100, 0.01);
            this.xSpeed = this.ySpeed = 0;
            this.x = lerp(this.x, this.target.x + fidelity / 2, 0.05);
            this.y = lerp(this.y, this.target.y + fidelity / 2, 0.05);
            this.timer += 1;
          } else if (dist < 10) {
            this.lightness = lerp(this.lightness, 100, 0.01);
            this.xSpeed = lerp(this.xSpeed, tx, 0.1);
            this.ySpeed = lerp(this.ySpeed, ty, 0.1);
            this.timer += 1;
          } else {
            this.xSpeed = lerp(this.xSpeed, tx, 0.02);
            this.ySpeed = lerp(this.ySpeed, ty, 0.02);
          }
        } else {
          this.ySpeed += 0.05;
          this.size = lerp(this.size, 1, 0.05);

          if (this.y > window.innerHeight) {
            shards.forEach((shard, idx) => {
              if (shard === this) {
                shards.splice(idx, 1);
              }
            });
          }
        }
        this.x = this.x + this.xSpeed;
        this.y = this.y + this.ySpeed;
      }
    }

    class Rocket {
      constructor() {
        const quarterW = window.innerWidth / 4;
        this.x = quarterW + Math.random() * (window.innerWidth - quarterW);
        this.y = window.innerHeight - 15;
        this.angle = Math.random() * Math.PI / 4 - Math.PI / 6;
        this.blastSpeed = 6 + Math.random() * 7;
        this.shardCount = Math.min(15 + Math.floor(Math.random() * 15), window.innerWidth / 20);
        this.xSpeed = Math.sin(this.angle) * this.blastSpeed;
        this.ySpeed = -Math.cos(this.angle) * this.blastSpeed;
        this.hue = Math.floor(Math.random() * 360);
        this.trail = [];
      }
      draw(ctx) {
        ctx.save();
        ctx.translate(this.x, this.y);
        ctx.rotate(Math.atan2(this.ySpeed, this.xSpeed) + Math.PI / 2);
        ctx.fillStyle = `hsl(${this.hue}, 100%, 50%)`;
        ctx.fillRect(0, 0, 5, 15);
        ctx.restore();
      }
      update() {
        this.x = this.x + this.xSpeed;
        this.y = this.y + this.ySpeed;
        this.ySpeed += 0.1;
      }

      explode() {
        for (let i = 0; i < this.shardCount; i++) {
          shards.push(new Shard(this.x, this.y, this.hue));
        }
      }
    }

    const animationCanvas = document.getElementById('animationCanvas');
    const ctx2 = animationCanvas.getContext('2d');
    const rockets = [];
    const shards = [];
    const targets = [];
    const fidelity = 3;
    let counter = 0;

    animationCanvas.width = window.innerWidth;
    animationCanvas.height = window.innerHeight;

    const textElement = document.getElementById('text');
    const textWidth = textElement.offsetWidth;
    let scrollOffset = window.innerWidth;
    const scrollSpeed = 0.5; // 降低滚动速度

    (function loop() {
      ctx2.fillStyle = "rgba(0, 0, 0, .1)";
      ctx2.fillRect(0, 0, window.innerWidth, window.innerHeight);
      counter += 1;

      if (counter % 15 === 0) {
        rockets.push(new Rocket());
      }
      rockets.forEach((r, i) => {
        r.draw(ctx2);
        r.update();
        if (r.ySpeed > 0) {
          r.explode();
          rockets.splice(i, 1);
        }
      });

      shards.forEach((s, i) => {
        s.draw(ctx2);
        s.update();

        if (s.timer >= s.ttl || s.lightness >= 99) {
          ctx2.fillRect(s.target.x, s.target.y, fidelity + 1, fidelity + 1);
          shards.splice(i, 1);
        }
      });

      textElement.style.transform = `translateX(${scrollOffset}px)`;
      scrollOffset -= scrollSpeed;
      if (scrollOffset < -textWidth) {
        scrollOffset = window.innerWidth; // 重置滚动位置
      }

      requestAnimationFrame(loop);
    })();

    const lerp = (a, b, t) => Math.abs(b - a) > 0.1 ? a + t * (b - a) : b;

    function getTarget() {
      if (targets.length > 0) {
        const idx = Math.floor(Math.random() * targets.length);
        let { x, y } = targets[idx];
        targets.splice(idx, 1);

        x += window.innerWidth / 2 - textWidth / 2;
        y += window.innerHeight / 2 - 60 / 2;

        return { x, y };
      }
    }

    document.addEventListener('touchstart', (e) => {
      const x = e.touches[0].clientX;
      const y = e.touches[0].clientY;
      for (let i = 0; i < 50; i++) {
        shards.push(new Shard(x, y, Math.floor(Math.random() * 360)));
      }
    });
  </script>
</body>
</html>